package com.aloda.ojuser.pojo.enums;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;

public enum UserStatusEnum {
    BANNED(1,"禁用"),
    NORMAL(0,"正常")
    ;

    private  int code;

    private  String desc;

    UserStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param code
     * @return
     */
    public static UserStatusEnum getEnumByValue(int code) {
        if (ObjectUtil.isEmpty(code)) {
            return null;
        }
        for (UserStatusEnum anEnum : UserStatusEnum.values()) {
            if (anEnum.code == code) {
                return anEnum;
            }
        }
        return null;
    }

    public static UserStatusEnum fromCode(int code) {
        for (UserStatusEnum status : UserStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的用户状态码: " + code);
    }
}
